<?php
class PageModel {
	
	private $user;
	private $book;
	
	public function setBook($book) {
		$this->book = $book;
	}
	
	public function getBook() {
		return $this->book;
	}
	
	public function setUser($user) {
		$this->user = $user;
	}
	
	public function getUser() {
		return $this->user;
	}
	
    /**
     * Return book condition array, e.g
     * {
     *     "New" => 2
     *     "Old" => 4
     * }
     * @param $book
     * @param $cityId top city id
     */
    public function getBookConditionsAmount($cityId) {
        $userBookCondition = new UserBookCondition();
        $userBooks = Book::getUserBooks(self::getBook());
        $ret = array(
            "New" => 0,
            "eBook" => 0,
            "Used" => 0
        );
        foreach ($userBooks as $userBook) {
        	$user = UserBook::getUser($userBook);
        	if (User::getTopCity($user)->id == $cityId) {
	            $conditionArr = explode(",", $userBook->condition);
	            foreach ($conditionArr as $conditionId) {
	                $condition = $userBookCondition->findById($conditionId);
	                $ret[$condition->condition] ++;
	            }
        	}
        }
        return $ret;
    }
}
?>